
# from time import sleep
# from selenium import webdriver
# from selenium.webdriver import ActionChains
# from selenium.webdriver.common.by import By
#
# driver = webdriver.Chrome() #创建浏览器对象
# # 放大浏览器页面
# driver.maximize_window()
# # 2.输入访问地址（URL）
# driver.get("http://121.43.169.97:8848/pageA.html")
#
# # 1).点击 alert 按钮
# driver.find_element_by_css_selector("#alerta").click()
# # 2).关闭警告框
# # 3).输入用户名：admin
# driver.find_element_by_css_selector("#userA").send_keys("admin")
#
#
# # sleep(3)
# # driver.quit()




from time import sleep
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

driver = webdriver.Chrome() #创建浏览器对象
# 放大浏览器页面
driver.maximize_window()
# 2.输入访问地址（URL）
driver.get("http://121.43.169.97:8848/pageA.html")

# 1).点击 alert 按钮
driver.find_element_by_css_selector("#alerta").click()
sleep(2)

# 获取弹框对象
al = driver.switch_to.alert
# 获取文本信息
print("警告框信息:", al.text)
# 处理 对话框
# 1同意
al.accept()


# 2).关闭警告框
# 3).输入用户名：admin
driver.find_element_by_css_selector("#userA").send_keys("admin")

sleep(2)
# 2取消
# al.dismiss()
driver.find_element_by_css_selector("#confirma").click()
print("确认框信息:", al.text)
al.dismiss()

sleep(3)
driver.quit()
